package programmercarl.回溯.C2;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

class Solution1 {

    private List<List<Integer>> ans = new ArrayList<>();
    private LinkedList<Integer> curr = new LinkedList<>();

    public List<List<Integer>> combine(int n, int k) {
        backtrack(n, k, 1);
        return ans;
    }

    private void backtrack(int n, int k, int start) {
        if (curr.size() == k) {
            ans.add(new ArrayList<>(curr));
        }
        for (int i = start; i <= n; i++) {
            curr.add(i);
            backtrack(n, k, i + 1);
            curr.removeLast();
        }
    }
}